import re


# 1. 识别后续的字符串：'bat', 'bit', 'but', 'hat', 'hit'和'hut'
for str_t in ['bat', 'bit', 'but', 'hat', 'hit','hut']:
    result = re.match(r'b.t|h.t', str_t).group()
    print(result)

# 2. 匹配由单个空格分隔的任意单词对，也就是姓和名

for name in ['tom dean', 'jack dd', 'toms dean']:
    print(re.match(r'\w+\s\w+', name).group())

# 3.

# 4. 匹配所有有效python标识符的结合
s = r'[a-zA-Z0-9_]+'

# 6. 匹配以www起始，以.com结尾的web域名
s = r'(?:www|http|https)://www\.\w+\.(?:com|net|edu)'
for website in ['www://www.yahoo.com', 'http://www.footthill.edu']:
    print(re.match(s, website).group())

# 13 type()
for type_s in [1, 1.1, dir, '1']:
    result = str(type(type_s))
    print(re.search(r"'(\w+)'", result).group())

# 14 匹配月份
for month in ['01', '04', '11', '12']:
    print(re.match(r'(1[0-2]|0?[1-9])', month).group())

# 15 匹配信用卡好
credit_num = ['1111-222222-12345', '2222-1345-5678-0987', '1222-2222-3333-4444']
for i in credit_num:
    if len(i) == 17:
        print(re.match(r'\d{4}-\d{6}-\d{5}', i).group())
    else:
        print(re.match(r'\d{4}-\d{4}-\d{4}-\d{4}', i).group())
